package de.reondo.jos;

import java.io.Serializable;

/**
 * Maintains all relevant information about a class for dependency analysis.
 * Introduced because using Class directly seems to consume too much memory.
 * 
 * @author dw
 *
 */
public class ClassInfo implements Serializable, Comparable<ClassInfo> {

    
    /**
     * 
     */
    private static final long serialVersionUID = 2649930685092814475L;
    private String name;
    private String pkg;

    public ClassInfo(Class<?> cls) {
        name = cls.getName();
        pkg = (cls.getPackage() == null) ? "" : cls.getPackage().getName();
    }
    
    public String getName() {
        return name;
    }

    public String getPackage() {
        return pkg;
    }

    @Override
    public int compareTo(ClassInfo o) {
        int c = name.compareTo(o.name);
        if (c != 0) 
            return c;
        return pkg.compareTo(o.pkg);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((pkg == null) ? 0 : pkg.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        ClassInfo other = (ClassInfo) obj;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (pkg == null) {
            if (other.pkg != null)
                return false;
        } else if (!pkg.equals(other.pkg))
            return false;
        return true;
    }

    
}
